<?php
namespace appcode\enum;

interface IEnumBaseClass {
    public static function GetArray();
    public static function GetById($id);
    public static function GetByName($name);
    public static function GetDefaultId();
    public static function GetDefaultName();
}

class EnumBaseClassHelper{
    public static function GetById($array, $id){
        return self::Get($array, $id, true);
    }

    public static function GetByName($array, $name){
        return self::Get($array, $name, false);
    }

    public static function GetDefaultId($array, $name){
        return self::Get($array, $name, false);
    }

    private static function Get($array, $object, $isById){
        if(!empty($array)){
            foreach($array as $id => $name){
                if($isById){
                    if($id == $object){
                        return $name;
                    }
                }
                else{
                    if($name == $object){
                        return $id;
                    }
                }
            }
        }
        return null;
    }
}
